package com.topcoder.srm511;

public class GameOfLifeDivTwo {
	public String theSimulation(String init, int T) {
		int N = init.length();
		int[] a = new int[N];
		for (int i=0; i<N; i++) a[i] = init.charAt(i) - '0';
		int[] b = new int[N];
		
		int[] t;
		for (int i=0; i<T; i++) {
			for (int j=0; j<N; j++) {
				int s = (j==0? a[N-1] : a[j-1]) + a[j] + (j==N-1? a[0] : a[j+1]);
				b[j] = s>=2? 1 : 0;
			}
			t = a;
			a = b;
			b = t;
		}
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<N; i++) sb.append(a[i]);
		return sb.toString();
	}
}
